<?php
$username=$_POST['username'];
$password=$_POST['password'];
$cpassword=$_POST['cpassword'];
$submit=$_POST['submit'];

if($_POST['sex']=='') 
{	
	$sex=rand(1,4);
}
else $sex=$_POST['sex'];

$userface='photo/userface.jpg';
$time=time();
$str_pw=strlen($password);


if(isset($submit))
{
	if($submit=='注册') //存在就执行
	{
		include_once 'mysql_connect.php';
			
		if($username=='')
		{
			$message="<a href=register.php><font color=red>用户名不能为空</font></a><br />";
			header("location:show.php?show=$message");
		}
		elseif(($str_pw< 7) || ($str_pw > 33))
		{
			$message="此密码长度为<font color=red>$str_pw</font><br /><a href=register.php>请确保密码长度为7-32之间</a><br />";
			header("location:show.php?show=$message");
		}
		elseif($password != $cpassword)
		{
			$message="<a href=register.php>2 次密码不一致</a><br />";
			header("location:show.php?show=$message");	
		}
		else
		{
			$password=md5($cpassword);
			$insert_user=mysql_query("INSERT INTO `member` (`uid`, `username`, `password`, `sex`, `userface`, `regtime`) VALUES (NULL, '$username', '$password', '$sex', '$userface', '$time')");
			
			if($insert_user)
			{
				$uid=mysql_query(" SELECT `uid` FROM `member` WHERE `username`='$username' ");
				$uid=mysql_result($uid,0);
				header("location:user_zone.php?uid=$uid");	
			}
			else
			{
				$message="<a href=register.php>用户名<font color=red>$username</font>已被注册</a><br />";
				header("location:show.php?show=$message");	
			}
			
		}
	}
	
	if($submit=='登陆')
	{
		header("location:login.php");
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>会员注册</title>
</head>

<body>
&nbsp;
<hr />
&nbsp;
<form action="register.php" method="post">
<table border="1"  align="center">
	<tr align="center">
		<td colspan="2">会员注册</td>
	</tr>
	<tr>
		<td width="93" align="right">用户名：</td>
		<td width="196"><input type="text" name="username" maxlength="25" size="25" /><font color="#FF0000">*</font></td></tr>
	<tr>
		<td align="right">密&nbsp;&nbsp;&nbsp;&nbsp;码：</td>
		<td><input type="password" name="password" maxlength="25" size="25"/><font color="#FF0000">*</font></td>
	</tr>
	<tr>
		<td align="right">确认密码：</td>
		<td><input type="password" name="cpassword" maxlength="25" size="25"/><font color="#FF0000">*</font></td>
	</tr>
	<tr>
		<td align="right">性&nbsp;&nbsp;&nbsp;&nbsp;别：</td>
		<td><input type="radio" name="sex" value="1" />男<input type="radio" name="sex" value="2" />女</td>
	</tr>
	<tr align="center">
		<td colspan="2"><input type="submit" name="submit" value="注册" /><input type="submit" name="submit" value="登陆" /></td>
	</tr>
</table>
</form>
</body>
</html>
